<?php 

class Model_Users_Users extends Zend_Db_Table {
	protected $_name = 'users';
	
	public function fetchItemsSelect($sort, $sortdir) {
		
		$select = $this->select();
		$select -> order($sort.' '.$sortdir);
		
		return $select;
	}
	
	public function fetchItemForEdit($id) {
		$items = $this->find($id);
		if (count($items)) {
			$item = $items->current()->toArray();
			unset($item['password']);
			unset($item['verificationKey']);
			unset($item['created']);
			return $item;
		}
		return false;
	}
	
	protected function checkData($data) {
		if (isset($data['password'])) {
			if (!empty($data['password']))
				$data['password'] = sha1($data['password']);
			else 
				unset($data['password']);
		}
		return $data;
	}
	
	public function update($data, $where) {
		if (is_int($where)) {
			$where = "id=$where";
		}
		return parent::update($this->checkData($data), $where);
	}
	
	public function insert($data) {
		return parent::insert($this->checkData($data));
	}
	
}